package com.crl.manager
{
	import com.crl.manager.resource.ResourceBundle;
	import com.crl.net.ResourceToken;
	
	import flash.utils.Dictionary;
	
	public class ResourceManager
	{
		private var map:Dictionary;
		public function ResourceManager()
		{
			map=new Dictionary();
		}
		
		public static var instance:ResourceManager=new ResourceManager();
		
		public function addBundle(value:ResourceBundle):void{
			map[value.name]=value;
		}
		
		public function removeBundle(name:String):void{
			if(map.hasOwnProperty(name)){
				map[name]=null;
				delete map[name];
			}
		}
		
		public function getBundle(name:String):ResourceBundle{
			return map[name];
		}
		
		public function getResource(bundleName:String,key:String):*{
			var bundle:ResourceBundle=map[bundleName];
			
			if(bundle){
				return bundle.getObejct(key);
			}
			return null;
		}
		
		public function saveResouce(boundleName:String,key:String,data:*):void{
			var bundle:ResourceBundle=map[boundleName];
			
			if(bundle==null){
				bundle=new ResourceBundle(boundleName);
			}
			bundle.setObject(key,data);
		}
		
	}
}